import { ApiConfig } from '../../utils/ApiConfig.js';
import { Token } from '../../utils/Token.js';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    showIcon:true,
    bannerList: [],
    needList: [],
    supplyList: [],
    produceList: [],
    typeList: [],
  },

  clickRedirect:function(e){
    wx.redirectTo({
      url: '../form/form'
    })
  },
  
  handleInputChange(e){
    let value = e.detail.value;
    if( value ){
      this.setData({showIcon:false});
    }
  },

  getBannerList(num = 3){
    let that=this
    wx.request({
      url: ApiConfig.restUrl + 'api/banner',
      data:{limit:num},
      header:{
        'token': wx.getStorageSync('token'),
      },
      success (response){
         that.setData({bannerList:response.data.data});
        console.log(that.setData);
      }
    })
  },

  getSupplyList(num){
    let that = this
    wx.request({
      url: ApiConfig.restUrl + 'api/orders',
      data:{limit:num},
      header:{
        'token': wx.getStorageSync('token')
      },
      success (response){
        console.log({needList:response.data.data.data.need});
        that.setData({needList:response.data.data.data.supply});
        that.setData({supplyList:response.data.data.data.need});
      }
    })
  },

  getCategoryList(){
    let that = this
    wx.request({
      url: ApiConfig.restUrl +'api/catrgory',
      header:{
        'token': wx.getStorageSync('token')
      },
      success (r){
        console.log(r.data);
        that.setData({typeList:r.data.data});
      }
    })
  },

  getQuotedList(){
    let that = this
    wx.request({
      url: ApiConfig.restUrl +'api/quoted',
      header:{
        'token': wx.getStorageSync('token')
      },
      success (r){
        console.log(r.data)
        that.setData({produceList:r.data.data})
      }
    })
  },
  
  onLoad:function(){
    this.getBannerList(3);
    this.getSupplyList(4);
    this.getCategoryList();
    this.getQuotedList();
  }
  

})